﻿using Circus.CodeEditor;
using Circus.CodeEditor.CodeCompletion;
using Circus.CodeEditor.Dialogs;
using Circus.CodeEditor.Serialization;
using Circus.CodeEditor.TextSource;
using Circus.Syntax;
using Circus.Syntax.CodeCompletion;
using Circus.Syntax.Lexer;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Xml.Serialization;
namespace Circus.CodeEditor {
    public partial class CodeEditor {
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SearchDialog SearchDialog {
            get {
                if (this.searchDialog == null) {
                    this.searchDialog = new SearchDialog();
                    this.searchDialog.SearchSettings.SearchOptions = this.searchOptions;
                }
                return this.searchDialog;
            }
            set {
                if (this.searchDialog != value) {
                    this.searchDialog = value;
                    this.OnSearchDialogChanged();
                }
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual DlgSyntaxSettings EditorSettingsDialog {
            get {
                if (this.editorSettingsDialog == null) {
                    this.editorSettingsDialog = new DlgSyntaxSettings();
                    this.editorSettingsDialog.HelpRequested += new HelpEventHandler(this.syntaxSettings.OnHelpRequest);
                }
                return this.editorSettingsDialog;
            }
            set {
                if (this.editorSettingsDialog != value) {
                    this.editorSettingsDialog = value;
                    this.OnEditorSettingsDialogChanged();
                }
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual DlgGoto GotoLineDialog {
            get {
                if (this.gotoLineDialog == null) {
                    this.gotoLineDialog = new DlgGoto();
                }
                return this.gotoLineDialog;
            }
            set {
                if (this.gotoLineDialog != value) {
                    this.gotoLineDialog = value;
                    this.OnGotoLineDialogChanged();
                }
            }
        }


        protected virtual Printing CreatePrinting() {
            return new Printing(this);
        }


        protected Cursor IncrementalSearchCursor {
            get {
                if (this.incrementalSearchCursor == null) {
                    Type type = typeof(CodeEditor);
                    this.incrementalSearchCursor = Resources.loadCursor(Resources.getStream("Images.IncrementalSearch.cur"));
                }
                return this.incrementalSearchCursor;
            }
        }
        protected Cursor ReverseIncrementalSearchCursor {
            get {
                if (this.reverseIncrementalSearchCursor == null) {
                    Type type = typeof(CodeEditor);
                    this.reverseIncrementalSearchCursor = Resources.loadCursor(Resources.getStream("Images.ReverseIncrementalSearch.cur"));
                }
                return this.reverseIncrementalSearchCursor;
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual bool InIncrementalSearch {
            get {
                return this.inIncrementalSearch;
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual bool InCycledSearch {
            get {
                return SearchManager.SharedSearch.Shared ? SearchManager.SharedSearch.InCycledSearch : this.searchCycled;
            }
            set {
                if (SearchManager.SharedSearch.Shared) {
                    SearchManager.SharedSearch.InCycledSearch = value;
                } else {
                    this.searchCycled = value;
                }
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual string IncrementalSearchString {
            get {
                return this.inIncrementalSearch ? this.searchText : string.Empty;
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual Point SearchPos {
            get {
                return this.searchPos;
            }
            set {
                if (this.searchPos != value) {
                    this.searchPos = value;
                    this.OnSearchPosChanged();
                }
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SearchOptions SearchOptions {
            get {
                return this.searchOptions;
            }
            set {
                if (this.searchOptions != value) {
                    this.searchOptions = value;
                    this.OnSearchOptionsChanged();
                }
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual int SearchLen {
            get {
                return this.searchLen;
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual bool FirstSearch {
            get {
                return SearchManager.SharedSearch.Shared ? SearchManager.SharedSearch.FirstSearch : this.firstSearch;
            }
            set {
                if (this.FirstSearch != value) {
                    this.Source.BeginUpdate(UpdateReason.Other);
                    try {
                        if (SearchManager.SharedSearch.Shared) {
                            SearchManager.SharedSearch.FirstSearch = value;
                        } else {
                            this.firstSearch = value;
                        }
                        this.Source.State |= NotifyState.FirstSearchChanged;
                    } finally {
                        this.Source.EndUpdate();
                    }
                }
            }
        }

        public bool SearchGlobal {
            get {
                return this.searchGlobal;
            }
            set {
                if (this.searchGlobal != value) {
                    this.searchGlobal = value;
                    this.OnSearchGlobalChanged();
                }
            }
        }


        public virtual DialogResult DisplayGotoLineDialog() {
            return this.DisplayGotoLineDialog(null);
        }
        public virtual DialogResult DisplayGotoLineDialog(IWin32Window owner) {
            int y = this.Position.Y;
            DialogResult dialogResult = (this.GotoLineDialog != null) ? this.GotoLineDialog.Execute(this, this.Lines.Count, ref y, owner) : DialogResult.None;
            if (dialogResult == DialogResult.OK) {
                this.Source.BeginUpdate();
                try {
                    this.Source.State |= NotifyState.CenterLine;
                    this.MoveToLine(y);
                } finally {
                    this.Source.EndUpdate();
                }
            }
            return dialogResult;
        }

        private bool NeedIncrementalSearch(char key) {
            bool flag = this.inIncrementalSearch;
            if (flag) {
                this.IncrementalSearch(key.ToString(), false);
            }
            return flag;
        }
        private void CheckIncrementalSeacrh() {
            if (!this.incrSearchFlag) {
                this.FinishIncrementalSearch();
            }
        }
     
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public Circus.CodeEditor.Dialogs.SyntaxSettings SyntaxSettings {
            get {
                return this.syntaxSettings;
            }
        }


        public virtual DialogResult DisplaySearchDialog() {
            return this.DisplaySearchDialog(null);
        }
        public virtual DialogResult DisplaySearchDialog(IWin32Window owner) {
            this.isReplace = false;
            DialogResult result;
            if (this.SearchDialog != null) {
                if (this.Selection.SelectionRect.Height > 1) {
                    this.SearchDialog.SearchSettings.SearchOptions |= SearchOptions.SelectionOnly;
                } else {
                    this.SearchDialog.SearchSettings.SearchOptions &= ~SearchOptions.SelectionOnly;
                }
                result = this.SearchDialog.Execute(this, false, false, owner);
            } else {
                result = DialogResult.None;
            }
            return result;
        }
        public DialogResult DisplayModalSearchDialog() {
            return this.DisplayModalSearchDialog(null);
        }
        public DialogResult DisplayModalSearchDialog(IWin32Window owner) {
            this.isReplace = false;
            DialogResult result;
            if (this.SearchDialog != null) {
                if (this.Selection.SelectionRect.Height > 1) {
                    this.SearchDialog.SearchSettings.SearchOptions |= SearchOptions.SelectionOnly;
                } else {
                    this.SearchDialog.SearchSettings.SearchOptions &= ~SearchOptions.SelectionOnly;
                }
                result = this.SearchDialog.Execute(this, true, false, owner);
            } else {
                result = DialogResult.None;
            }
            return result;
        }
        public virtual DialogResult DisplayReplaceDialog() {
            return this.DisplayReplaceDialog(null);
        }
        public virtual DialogResult DisplayReplaceDialog(IWin32Window owner) {
            return (this.SearchDialog != null) ? this.SearchDialog.Execute(this, false, true, owner) : DialogResult.None;
        }
        public DialogResult DisplayModalReplaceDialog() {
            return this.DisplayModalReplaceDialog(null);
        }
        public DialogResult DisplayModalReplaceDialog(IWin32Window owner) {
            this.isReplace = true;
            return (this.SearchDialog != null) ? this.SearchDialog.Execute(this, true, true, owner) : DialogResult.None;
        }
        public virtual DialogResult DisplayEditorSettingsDialog(EditorSettingsTab hiddenTabs, IWin32Window owner) {
            DialogResult result;
            if (this.EditorSettingsDialog != null) {
                this.syntaxSettings.LoadFromEdit(this);
                this.EditorSettingsDialog.SyntaxSettings = this.syntaxSettings;
                DialogResult dialogResult = this.EditorSettingsDialog.Execute(hiddenTabs, owner);
                if (dialogResult == DialogResult.OK) {
                    this.syntaxSettings.Assign(this.EditorSettingsDialog.SyntaxSettings);
                    this.syntaxSettings.ApplyToEdit(this);
                }
                result = dialogResult;
            } else {
                result = DialogResult.None;
            }
            return result;
        }
        public virtual DialogResult DisplayEditorSettingsDialog(EditorSettingsTab hiddenTabs) {
            return this.DisplayEditorSettingsDialog(hiddenTabs, null);
        }
        public virtual DialogResult DisplayEditorSettingsDialog() {
            return this.DisplayEditorSettingsDialog(EditorSettingsTab.None, null);
        }

        protected bool DoReplaceAll(string str, string replaceWith, SearchOptions options, Regex expr, out int count) {
            bool flag;
            return this.DoReplaceAll(str, replaceWith, options, expr, out count, out flag);
        }
        protected bool DoReplaceAll(string str, string replaceWith, SearchOptions options, Regex expr, out int count, out bool abort) {
            this.replaceText = replaceWith;
            abort = false;
            this.FirstSearch = true;
            count = 0;
            bool result = false;
            bool flag = (options & SearchOptions.SelectionOnly) != SearchOptions.None;
            bool flag2 = (options & SearchOptions.PromptOnReplace) == SearchOptions.None;
            this.searchUpdateCount++;
            if (flag2) {
                this.selection.Invalidate();
                this.Source.BeginUpdate(UpdateReason.Other);
            }
            int index = this.StorePositionWithUndo(this.Position);
            try {
                bool flag3 = false;
                while (this.Find(str, options, expr, this.FirstSearch, flag2)) {
                    result = true;
                    if (this.ReadOnly) {
                        break;
                    }
                    int index2 = this.StorePosition(this.searchStartPos, true);
                    try {
                        DialogResult dialogResult = this.DoReplace(str, replaceWith, flag3 ? (options & ~SearchOptions.CycledSearch & ~SearchOptions.PromptOnReplace) : (options & ~SearchOptions.CycledSearch), this.searchMatch, ref flag3);
                        if (this.searchLen == 0) {
                            if ((options & SearchOptions.BackwardSearch) == SearchOptions.None) {
                                if (this.searchPos.X < this.Lines.GetLength(this.searchPos.Y)) {
                                    this.searchPos.X = this.searchPos.X + (replaceWith.Length + 1);
                                } else {
                                    if (this.searchPos.Y == this.Lines.Count - 1) {
                                        break;
                                    }
                                    this.searchPos.X = this.searchPos.X + replaceWith.Length;
                                    this.searchPos.Y = this.searchPos.Y + 1;
                                }
                            } else {
                                if (this.searchPos.X > replaceWith.Length) {
                                    this.searchPos.X = this.searchPos.X - (replaceWith.Length + 1);
                                } else {
                                    if (this.searchPos.Y == 0) {
                                        break;
                                    }
                                    this.searchPos.Y = this.searchPos.Y - 1;
                                    this.searchPos.X = this.Lines.GetLength(this.searchPos.Y) - replaceWith.Length;
                                }
                            }
                            this.Source.Position = this.searchPos;
                        }
                        if (dialogResult == DialogResult.Cancel) {
                            abort = true;
                            break;
                        }
                        if (dialogResult == DialogResult.Yes) {
                            count++;
                        }
                    } finally {
                        this.searchStartPos = this.RestorePosition(index2);
                    }
                }
            } finally {
                this.RestorePositionWithUndo(index);
                if (flag2) {
                    this.Source.EndUpdate();
                }
                if (flag) {
                    this.Selection.SetSelection(this.searchSelType, this.searchSelRect);
                } else {
                    this.Selection.Clear();
                }
                this.searchUpdateCount--;
            }
            return result;
        }
        protected void InitSearchPos(SearchOptions options, bool update) {
            if ((options & SearchOptions.EntireScope) != SearchOptions.None) {
                if ((options & SearchOptions.BackwardSearch) != SearchOptions.None) {
                    if ((options & SearchOptions.SelectionOnly) != SearchOptions.None && !this.Selection.IsEmpty) {
                        this.searchPos = new Point(this.Selection.SelectionRect.Right, this.Selection.SelectionRect.Bottom);
                    } else {
                        this.searchPos = new Point(this.Lines[this.Lines.Count - 1].Length, this.Lines.Count - 1);
                    }
                } else {
                    if ((options & SearchOptions.SelectionOnly) != SearchOptions.None && !this.Selection.IsEmpty) {
                        this.searchPos = this.Selection.SelectionRect.Location;
                    } else {
                        this.searchPos = new Point(0, 0);
                    }
                }
            } else {
                if (update && (options & SearchOptions.SelectionOnly) != SearchOptions.None && !this.Selection.IsEmpty) {
                    if ((options & SearchOptions.BackwardSearch) != SearchOptions.None) {
                        this.searchPos = new Point(this.Selection.SelectionRect.Right, this.Selection.SelectionRect.Bottom);
                    } else {
                        this.searchPos = this.Selection.SelectionRect.Location;
                    }
                } else {
                    this.searchPos = this.Source.Position;
                }
            }
            if (SearchManager.SharedSearch.Shared) {
                SearchManager.SharedSearch.UpdateSearch(this, update);
            }
        }
        protected bool PerformSearch(string str, SearchOptions options, Regex expression, ref Point searchPos) {
            bool flag;
            if ((options & SearchOptions.SelectionOnly) != SearchOptions.None && !this.Selection.IsEmpty) {
                Point position = this.Selection.TextToSelectionPoint(searchPos);
                flag = (new TextStrings(null) {
                    Text = this.Selection.SelectedText
                }).Find(str, options, expression, ref position, out this.searchLen, out this.searchMatch);
                if (flag) {
                    searchPos = this.Selection.SelectionToTextPoint(position);
                }
            } else {
                if ((options & SearchOptions.SearchHiddenText) == SearchOptions.None) {
                    Point position = this.displayLines.PointToDisplayPoint(searchPos.X, searchPos.Y, false);
                    this.displayLines.SuppressTabs = true;
                    try {
                        flag = this.displayLines.Find(str, options, expression, ref position, out this.searchLen, out this.searchMatch);
                        if (flag) {
                            searchPos = this.displayLines.DisplayPointToPoint(position);
                            if (expression != null && (expression.Options & RegexOptions.Multiline) != RegexOptions.None) {
                                Point position2 = TextStrings.AbsolutePositionToTextPoint(this.displayLines, TextStrings.TextPointToAbsolutePosition(this.displayLines, position, this.displayLines.LineTerminator) + this.searchLen, this.displayLines.LineTerminator);
                                position2 = this.displayLines.DisplayPointToPoint(position2);
                                this.searchLen = this.Lines.TextPointToAbsolutePosition(position2) - this.Lines.TextPointToAbsolutePosition(searchPos);
                            } else {
                                this.searchLen = this.displayLines.DisplayPointToPoint(position.X + this.searchLen, position.Y, false, false, true).X - searchPos.X;
                            }
                        }
                    } finally {
                        this.displayLines.SuppressTabs = false;
                    }
                } else {
                    flag = this.Find(str, options, expression, ref searchPos, out this.searchLen, out this.searchMatch);
                }
            }
            return flag;
        }
        protected bool PerformCycledSearch(string str, SearchOptions options, Regex expression, ref Point searchPos) {
            bool flag = this.PerformSearch(str, options, expression, ref searchPos);
            if (flag && this.InCycledSearch) {
                if ((options & SearchOptions.BackwardSearch) != SearchOptions.None) {
                    flag = (searchPos.Y > this.searchStartPos.Y || (searchPos.Y == this.searchStartPos.Y && searchPos.X + this.searchLen > this.searchStartPos.X));
                } else {
                    flag = (searchPos.Y < this.searchStartPos.Y || (searchPos.Y == this.searchStartPos.Y && searchPos.X < this.searchStartPos.X));
                }
            }
            return flag;
        }
        protected bool InitCycledSearch(SearchOptions options) {
            bool result;
            if ((options & SearchOptions.CycledSearch) != SearchOptions.None) {
                this.InitSearchPos(options | SearchOptions.EntireScope, false);
                this.InCycledSearch = true;
                result = true;
            } else {
                result = false;
            }
            return result;
        }
        protected bool SelectionMatchesSearchText() {
            TextStrings textStrings = new TextStrings(null);
            string selectedText = this.selection.SelectedText;
            textStrings.Text = selectedText;
            Point point = ((this.searchOptions & SearchOptions.BackwardSearch) == SearchOptions.None) ? new Point(0, 0) : new Point(selectedText.Length, 0);
            int num;
            Match match;
            return textStrings.Find(this.searchText, this.searchOptions, this.searchExpression, ref point, out num, out match) && num == selectedText.Length && point.X == 0;
        }
        protected string GetReplaceString(string replaceWith, Match match) {
            string result = replaceWith;
            if (match != null && match.Success) {
                result = match.Result(replaceWith);
            }
            return result;
        }
        protected virtual DialogResult DoPromptOnReplace(string text, ref bool yesToAll) {
            DialogResult dialogResult = DialogResult.Yes;
            PromptReplaceEventArgs promptReplaceEventArgs = new PromptReplaceEventArgs(text, false, dialogResult, yesToAll);
            promptReplaceEventArgs.Text = text;
            promptReplaceEventArgs.Handled = false;
            promptReplaceEventArgs.DialogResult = DialogResult.Yes;
            promptReplaceEventArgs.YesToAll = false;
            if (this.PromptOnReplace != null) {
                this.PromptOnReplace(this, promptReplaceEventArgs);
                if (promptReplaceEventArgs.Handled) {
                    dialogResult = promptReplaceEventArgs.DialogResult;
                    yesToAll = promptReplaceEventArgs.YesToAll;
                }
            } else {
                yesToAll = true;
            }
            if (!promptReplaceEventArgs.Handled) {
                dialogResult = DlgSearchConfirmation.ShowWithCaption(text);
            }
            return dialogResult;
        }
        protected DialogResult DoReplace(string text, string replaceWith, SearchOptions options, Match match) {
            bool flag = false;
            return this.DoReplace(text, replaceWith, options, match, ref flag);
        }
        protected virtual DialogResult DoReplace(string text, string replaceWith, SearchOptions options, Match match, ref bool yesToAll) {
            Point position = this.Source.Position;
            this.replaceText = replaceWith;
            DialogResult dialogResult = DialogResult.Yes;
            if ((SearchOptions.PromptOnReplace & options) != SearchOptions.None) {
                dialogResult = this.DoPromptOnReplace(text, ref yesToAll);
            }
            if (dialogResult == DialogResult.OK) {
                int num = 0;
                this.DoReplaceAll(text, replaceWith, options & ~SearchOptions.PromptOnReplace, null, out num);
                dialogResult = DialogResult.Yes;
                this.searchOptions = options;
                yesToAll = true;
            } else {
                if (dialogResult == DialogResult.Yes) {
                    this.searchUpdateCount++;
                    this.Source.BeginUpdate(UpdateReason.Insert);
                    try {
                        int num2 = this.Source.TextPointToAbsolutePosition(new Point(this.searchSelRect.Right, this.searchSelRect.Bottom)) - this.Source.TextPointToAbsolutePosition(this.searchSelRect.Location);
                        this.Selection.Delete();
                        Point position2 = this.Position;
                        string text2 = this.GetReplaceString(replaceWith, match);
                        if (text2.IndexOf('\r') >= 0 || text2.IndexOf('\n') >= 0) {
                            this.Source.InsertBlock(text2);
                        } else {
                            if (text2.IndexOf("\\r") >= 0 || text2.IndexOf("\\n") >= 0) {
                                text2 = text2.Replace("\\r\\n", "\\n");
                                text2 = text2.Replace("\\r", "\\n");
                                string[] strings = text2.Split(new string[]
								{
									"\\n"
								}, StringSplitOptions.None);
                                this.Source.InsertBlock(strings);
                            } else {
                                this.Source.Insert(text2);
                            }
                        }
                        if ((options & SearchOptions.SelectionOnly) != SearchOptions.None) {
                            Point location = this.searchSelRect.Location;
                            int num3 = num2 + text2.Length - text.Length;
                            Point point = this.Source.AbsolutePositionToTextPoint(this.Source.TextPointToAbsolutePosition(this.searchSelRect.Location) + num3);
                            this.searchSelRect = new Rectangle(location.X, location.Y, point.X - location.X, point.Y - location.Y);
                        }
                        if ((SearchOptions.BackwardSearch & options) != SearchOptions.None) {
                            this.Position = position2;
                        }
                    } finally {
                        this.Source.EndUpdate();
                        this.searchUpdateCount--;
                    }
                }
            }
            return dialogResult;
        }
        protected bool DoReplace(string str, string replaceWith, SearchOptions options, Regex expr, bool silent) {
            return !this.Source.ReadOnly && this.Find(str, options, expr, this.FirstSearch, silent) && this.DoReplace(str, replaceWith, options, this.searchMatch) == DialogResult.Yes;
        }
        protected int DoMarkAll(string str, SearchOptions options, Regex expr, bool clearPrevious) {
            this.FirstSearch = true;
            int num = 0;
            IList<IBookMark> list = new List<IBookMark>();
            this.Selection.BeginUpdate();
            this.Source.BeginUpdate(UpdateReason.Other);
            try {
                if (clearPrevious) {
                    this.Source.BookMarks.ClearAllUnnumberedBookmarks();
                }
                while (this.Find(str, options, expr, this.FirstSearch, true)) {
                    bool flag = false;
                    if (this.Source.BookMarks.GetBookMarks(new Point(0, this.searchPos.Y), new Point(int.MaxValue, this.searchPos.Y), list) > 0) {
                        foreach (IBookMark current in list) {
                            if (current.Index == int.MaxValue) {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (this.searchLen == 0) {
                        if ((options & SearchOptions.BackwardSearch) == SearchOptions.None) {
                            if (this.searchPos.X < this.Lines.GetLength(this.searchPos.Y)) {
                                this.searchPos.X = this.searchPos.X + 1;
                            } else {
                                if (this.searchPos.Y == this.Lines.Count - 1) {
                                    break;
                                }
                                this.searchPos.X = 0;
                                this.searchPos.Y = this.searchPos.Y + 1;
                            }
                        } else {
                            if (this.searchPos.X > 0) {
                                this.searchPos.X = this.searchPos.X - 1;
                            } else {
                                if (this.searchPos.Y == 0) {
                                    break;
                                }
                                this.searchPos.Y = this.searchPos.Y - 1;
                                this.searchPos.X = this.Lines.GetLength(this.searchPos.Y);
                            }
                        }
                        this.Source.Position = this.searchPos;
                    }
                    if (!flag) {
                        this.Source.BookMarks.SetBookMark(new Point(0, this.searchPos.Y), int.MaxValue);
                    }
                    num++;
                }
            } finally {
                this.Source.EndUpdate();
                this.Selection.EndUpdate();
            }
            return num;
        }
        protected virtual void TextFound(SearchOptions options, Point position, int len, bool silent, bool multiline) {
            this.searchUpdateCount++;
            try {
                this.Source.BeginUpdate(UpdateReason.Navigate);
                try {
                    this.Source.State |= NotifyState.CenterLine;
                    if ((SearchOptions.BackwardSearch & options) != SearchOptions.None) {
                        this.Source.Position = position;
                    } else {
                        this.Source.Position = new Point(position.X + len, position.Y);
                    }
                } finally {
                    this.Source.EndUpdate();
                }
                if (this.selection.UpdateCount == 0) {
                    this.selection.UpdateSelStart(position);
                    this.selection.SetSelection(SelectionType.Stream, new Rectangle(position.X, position.Y, len, 0));
                    if (multiline) {
                        this.selection.SelectionLength = len;
                    }
                }
            } finally {
                this.searchUpdateCount--;
            }
            if (SearchManager.SharedSearch.Shared) {
                SearchManager.SharedSearch.OnTextFound(this);
            }
            if (!silent && this.searchDialog != null && this.searchDialog.Visible) {
                Rectangle rect = this.selection.SelectionToScreen();
                rect.Inflate(this.Painter.FontWidth, 0);
                rect.Location = base.PointToScreen(rect.Location);
                this.searchDialog.EnsureVisible(rect);
            }
        }
        protected virtual void OnSearchPosChanged() {
            this.FirstSearch = true;
        }
        protected virtual void OnSearchOptionsChanged() {
        }
        protected virtual void OnSearchDialogChanged() {
        }
        protected virtual void OnEditorSettingsDialogChanged() {
        }
        protected virtual void OnGotoLineDialogChanged() {
        }
        protected virtual void OnSearchGlobalChanged() {
        }
        protected void UpdateStartSearchPos() {
            if (this.searchUpdateCount == 0 && !this.FirstSearch) {
                this.searchStartPos = this.Position;
                this.InCycledSearch = false;
                if ((this.searchOptions & SearchOptions.SelectionOnly) != SearchOptions.None) {
                    this.searchSelType = this.Selection.SelectionType;
                    this.searchSelRect = this.Selection.SelectionRect;
                }
                this.InitSearchPos(this.searchOptions, true);
            }
        }
        public virtual bool Find(string text) {
            return this.Find(text, SearchOptions.None, null);
        }
        public virtual bool Find(string text, SearchOptions options) {
            return this.Find(text, options, null);
        }
        public virtual bool Find(string text, SearchOptions options, Regex expression) {
            this.FirstSearch = true;
            return this.Find(text, options, expression, this.FirstSearch, false);
        }
        public virtual bool Find(string text, SearchOptions options, Regex expression, bool firstSearch, bool silent) {
            bool flag = (options & SearchOptions.SelectionOnly) != SearchOptions.None && (!this.Selection.IsEmpty || (!firstSearch && this.searchSelType != SelectionType.None));
            if (flag && !firstSearch) {
                this.searchUpdateCount++;
                try {
                    this.Selection.SetSelection(this.searchSelType, this.searchSelRect);
                } finally {
                    this.searchUpdateCount--;
                }
            }
            bool result;
            if (flag && this.Selection.IsEmpty) {
                result = false;
            } else {
                this.searchMatch = null;
                if (firstSearch) {
                    this.searchText = text;
                    this.searchOptions = options;
                    this.searchExpression = expression;
                    this.searchSelType = (flag ? this.Selection.SelectionType : SelectionType.None);
                    this.searchSelRect = (flag ? this.Selection.SelectionRect : Rectangle.Empty);
                    this.searchStartPos = this.Position;
                    this.InCycledSearch = false;
                    this.InitSearchPos(options, false);
                } else {
                    if (!this.selection.IsEmpty && this.selection.UpdateCount == 0) {
                        if ((options & SearchOptions.BackwardSearch) == SearchOptions.None) {
                            if (flag) {
                                this.searchPos = this.Source.Position;
                            } else {
                                this.searchPos = new Point(this.selection.SelectionRect.Left, this.selection.SelectionRect.Top);
                                if (this.searchPos.X < this.Lines.GetLength(this.searchPos.Y)) {
                                    this.searchPos.X = this.searchPos.X + 1;
                                } else {
                                    this.searchPos.X = 0;
                                    this.searchPos.Y = this.searchPos.Y + 1;
                                }
                            }
                        } else {
                            if (flag) {
                                this.searchPos = this.Source.Position;
                            } else {
                                this.searchPos = new Point(this.selection.SelectionRect.Right, this.selection.SelectionRect.Bottom);
                                if (this.searchPos.X > 0) {
                                    this.searchPos.X = this.searchPos.X - 1;
                                } else {
                                    this.searchPos.Y = this.searchPos.Y - 1;
                                    this.searchPos.X = this.Lines.GetLength(this.searchPos.Y);
                                }
                            }
                        }
                    } else {
                        this.searchPos = this.Source.Position;
                        string text2 = (this.Source.Position.Y >= 0 && this.Source.Position.Y < this.DisplayLines.Count) ? this.DisplayLines[this.Source.Position.Y] : string.Empty;
                        if ((options & SearchOptions.RegularExpressions) != SearchOptions.None && this.searchPos.X == text2.Length) {
                            this.searchPos = new Point(0, this.searchPos.Y + 1);
                        }
                        if (this.searchLen == 0) {
                            if ((options & SearchOptions.BackwardSearch) == SearchOptions.None) {
                                if (this.searchPos.X < this.Lines.GetLength(this.searchPos.Y)) {
                                    this.searchPos.X = this.searchPos.X + 1;
                                } else {
                                    this.searchPos.X = 0;
                                    this.searchPos.Y = this.searchPos.Y + 1;
                                }
                            } else {
                                if (this.searchPos.X > 0) {
                                    this.searchPos.X = this.searchPos.X - 1;
                                } else {
                                    this.searchPos.Y = this.searchPos.Y - 1;
                                    this.searchPos.X = this.Lines.GetLength(this.searchPos.Y);
                                }
                            }
                        }
                    }
                }
                bool flag2 = this.PerformCycledSearch(text, options, expression, ref this.searchPos);
                if (!flag2 && !this.InCycledSearch) {
                    flag2 = (this.InitCycledSearch(options) && this.PerformCycledSearch(text, options, expression, ref this.searchPos));
                }
                if (flag2) {
                    this.TextFound(options, this.searchPos, this.searchLen, silent, expression != null && (expression.Options & RegexOptions.Multiline) != RegexOptions.None);
                    this.FirstSearch = false;
                } else {
                    if (this.InCycledSearch) {
                        this.searchStartPos = this.Position;
                        this.InCycledSearch = false;
                    }
                }
                result = flag2;
            }
            return result;
        }
        public virtual bool CycledSearch(string text, SearchOptions options, Regex expression, bool silent) {
            bool flag = this.InitCycledSearch(options) && this.PerformCycledSearch(text, options, expression, ref this.searchPos);
            if (flag) {
                this.TextFound(options, this.searchPos, this.searchLen, silent, expression != null && (expression.Options & RegexOptions.Multiline) != RegexOptions.None);
            } else {
                if (this.InCycledSearch) {
                    this.searchStartPos = this.Position;
                    this.InCycledSearch = false;
                }
            }
            return flag;
        }
        public void OnTextFound(string text, SearchOptions options, Regex expression, Match match, Point position, int len, bool silent, bool multiline) {
            this.searchText = text;
            this.searchOptions = options;
            this.searchExpression = expression;
            this.searchMatch = match;
            this.TextFound(options, position, len, silent, multiline);
        }
        public virtual bool Find(string text, SearchOptions options, Regex expression, IList<Range> ranges) {
            Point position = new Point(0, 0);
            if ((options & SearchOptions.SelectionOnly) != SearchOptions.None) {
                if (!this.Selection.IsEmpty) {
                    if ((SearchOptions.BackwardSearch & options) != SearchOptions.None) {
                        position.Offset(this.Selection.SelectionRect.Width, this.Selection.SelectionRect.Height);
                    }
                    TextStrings textStrings = new TextStrings(null);
                    textStrings.Text = this.Selection.SelectedText;
                    int num;
                    Match match;
                    while (textStrings.Find(text, options, expression, ref position, out num, out match)) {
                        Point point = this.Selection.SelectionToTextPoint(position);
                        ranges.Add(new Range(point.X, point.Y, point.X + num, point.Y));
                        if ((SearchOptions.BackwardSearch & options) == SearchOptions.None) {
                            position.X += num;
                        }
                    }
                }
            } else {
                int num;
                Match match;
                while (this.Find(text, options, expression, ref position, out num, out match)) {
                    ranges.Add(new Range(position.X, position.Y, position.X + num, position.Y));
                    if ((SearchOptions.BackwardSearch & options) == SearchOptions.None) {
                        position.X += num;
                    }
                }
            }
            return ranges.Count > 0;
        }
        public virtual bool FindNext() {
            bool result;
            if (this.CanFindNext()) {
                if (this.searchExpression != null && (this.searchExpression.Options & RegexOptions.RightToLeft) != RegexOptions.None) {
                    this.searchExpression = new Regex(this.searchExpression.ToString(), this.searchExpression.Options & ~RegexOptions.RightToLeft);
                }
                if (this.isReplace) {
                    result = this.Replace(this.searchText, this.replaceText, this.searchOptions & ~SearchOptions.BackwardSearch, this.searchExpression);
                } else {
                    result = this.Find(this.searchText, this.searchOptions & ~SearchOptions.BackwardSearch, this.searchExpression, this.FirstSearch, false);
                }
            } else {
                result = false;
            }
            return result;
        }
        public virtual bool FindPrevious() {
            bool result;
            if (this.CanFindPrevious()) {
                if (this.searchExpression != null && (this.searchExpression.Options & RegexOptions.RightToLeft) == RegexOptions.None) {
                    this.searchExpression = new Regex(this.searchExpression.ToString(), this.searchExpression.Options | RegexOptions.RightToLeft);
                }
                if (this.isReplace) {
                    result = this.Replace(this.searchText, this.replaceText, this.searchOptions | SearchOptions.BackwardSearch, this.searchExpression);
                } else {
                    result = this.Find(this.searchText, this.searchOptions | SearchOptions.BackwardSearch, this.searchExpression, this.FirstSearch, false);
                }
            } else {
                result = false;
            }
            return result;
        }
        public virtual bool FindNextSelected() {
            return this.CanFindNextSelected() && this.Find(this.selection.SelectedText, this.searchOptions & ~SearchOptions.BackwardSearch, this.searchExpression, this.FirstSearch, false);
        }
        public virtual bool FindPreviousSelected() {
            return this.CanFindPreviousSelected() && this.Find(this.selection.SelectedText, this.searchOptions | SearchOptions.BackwardSearch, this.searchExpression, this.FirstSearch, false);
        }
        public virtual bool CanFindNext() {
            return !this.firstSearch;
        }
        public virtual bool CanFindPrevious() {
            return !this.firstSearch;
        }
        public virtual bool CanFindNextSelected() {
            bool result;
            if (!this.selection.IsEmpty) {
                result = true;
            } else {
                if (this.GetTextToSearchAtCursor().Trim() != string.Empty) {
                    this.FirstSearch = true;
                    Point position = this.Position;
                    this.selection.SelectWord();
                    if (!this.selection.IsEmpty) {
                        this.selection.BeginUpdate();
                        try {
                            this.Position = position;
                        } finally {
                            this.selection.EndUpdate();
                        }
                    }
                }
                result = !this.selection.IsEmpty;
            }
            return result;
        }
        public virtual bool CanFindPreviousSelected() {
            bool result;
            if (!this.selection.IsEmpty) {
                result = true;
            } else {
                if (this.GetTextToSearchAtCursor().Trim() != string.Empty) {
                    this.FirstSearch = true;
                    Point position = this.Position;
                    this.selection.SelectWord();
                    if (!this.selection.IsEmpty) {
                        this.selection.BeginUpdate();
                        try {
                            this.Position = position;
                        } finally {
                            this.selection.EndUpdate();
                        }
                    }
                }
                result = !this.selection.IsEmpty;
            }
            return result;
        }
        public virtual bool Replace(string text, string replaceWith) {
            return this.Replace(text, replaceWith, SearchOptions.None, null);
        }
        public virtual bool Replace(string text, string replaceWith, SearchOptions options) {
            return this.Replace(text, replaceWith, options, null);
        }
        public virtual bool Replace(string text, string replaceWith, SearchOptions options, Regex expression) {
            this.FirstSearch = true;
            return this.DoReplace(text, replaceWith, options, expression, false);
        }
        public virtual bool ReplaceAll(string text, string replaceWith, out int count) {
            return this.ReplaceAll(text, replaceWith, SearchOptions.None, null, out count);
        }
        public virtual bool ReplaceAll(string text, string replaceWith, SearchOptions options, out int count) {
            return this.ReplaceAll(text, replaceWith, options, null, out count);
        }
        public virtual bool ReplaceAll(string text, string replaceWith, SearchOptions options, Regex expression, out int count) {
            return this.DoReplaceAll(text, replaceWith, options, expression, out count);
        }
        public virtual bool ReplaceAll(string text, string replaceWith, SearchOptions options, Regex expression, out int count, out bool abort) {
            return this.DoReplaceAll(text, replaceWith, options, expression, out count, out abort);
        }
        public virtual int MarkAll(string text, bool clearPrevious) {
            return this.DoMarkAll(text, SearchOptions.None, null, clearPrevious);
        }
        public virtual int MarkAll(string text, SearchOptions options, bool clearPrevious) {
            return this.DoMarkAll(text, options, null, clearPrevious);
        }
        public virtual int MarkAll(string text, SearchOptions options, Regex expression, bool clearPrevious) {
            return this.DoMarkAll(text, options, expression, clearPrevious);
        }
        public bool NeedReplaceCurrent() {
            return !this.FirstSearch && !this.Selection.IsEmpty && this.SelectionMatchesSearchText();
        }
        public virtual bool NeedReplaceCurrent(out Match match) {
            match = this.searchMatch;
            return this.NeedReplaceCurrent();
        }
        public virtual bool ReplaceCurrent(string replaceWith, SearchOptions options, Match match) {
            bool flag = !this.Source.ReadOnly && this.NeedReplaceCurrent();
            if (flag) {
                this.DoReplace(this.searchText, replaceWith, options, match);
            }
            return flag;
        }
        public virtual void StartIncrementalSearch() {
            this.StartIncrementalSearch(false);
        }
        public virtual void StartIncrementalSearch(bool backwardSearch) {
            this.inIncrementalSearch = true;
            this.incrSearchPosition = this.Position;
            this.incrStartSearchPosition = this.Position;
            this.searchText = string.Empty;
            this.searchOptions |= SearchOptions.FindTextAtCursor;
            this.searchStartPos = this.Position;
            this.InCycledSearch = false;
            if (backwardSearch) {
                this.searchOptions |= SearchOptions.BackwardSearch;
            } else {
                this.searchOptions &= ~SearchOptions.BackwardSearch;
            }
            this.Source.BeginUpdate(UpdateReason.Other);
            try {
                this.Source.State |= NotifyState.IncrementalSearchChanged;
            } finally {
                this.Source.EndUpdate();
            }
            if (base.IsHandleCreated) {
                OSUtils.SendMessage(base.Handle, 32, IntPtr.Zero, IntPtr.Zero);
            }
        }
        public virtual void FinishIncrementalSearch() {
            if (this.inIncrementalSearch) {
                this.inIncrementalSearch = false;
                this.Source.BeginUpdate(UpdateReason.Other);
                try {
                    this.Source.State |= NotifyState.IncrementalSearchChanged;
                } finally {
                    this.Source.EndUpdate();
                }
                if (base.IsHandleCreated) {
                    OSUtils.SendMessage(base.Handle, 32, IntPtr.Zero, IntPtr.Zero);
                }
            }
        }
        public virtual bool IncrementalSearch(string key, bool deleteLast) {
            bool flag = false;
            string text = this.searchText;
            this.incrSearchFlag = true;
            try {
                if (deleteLast) {
                    this.searchText = this.searchText.Remove(this.searchText.Length - 1, 1);
                } else {
                    this.searchText += key;
                }
                this.searchPos = this.incrStartSearchPosition;
                flag = this.PerformCycledSearch(this.searchText, this.searchOptions, this.searchExpression, ref this.searchPos);
                if (!flag && !this.InCycledSearch) {
                    flag = this.InitCycledSearch(this.searchOptions);
                    if (flag) {
                        this.incrStartSearchPosition = this.searchPos;
                        flag = this.PerformCycledSearch(this.searchText, this.searchOptions, this.searchExpression, ref this.searchPos);
                    }
                }
                if (flag) {
                    Point point = this.searchPos;
                    int num = this.searchLen;
                    this.Source.BeginUpdate(UpdateReason.Other);
                    try {
                        flag = true;
                        this.Position = new Point(point.X + num, point.Y);
                        this.Source.State |= NotifyState.IncrementalSearchChanged;
                    } finally {
                        this.Source.EndUpdate();
                    }
                    this.FirstSearch = false;
                    this.selection.SetSelection(SelectionType.Stream, new Rectangle(point.X, point.Y, num, 0));
                } else {
                    if (deleteLast) {
                        if (this.searchText == string.Empty) {
                            this.selection.Clear();
                        }
                        this.Source.BeginUpdate(UpdateReason.Other);
                        try {
                            if (this.searchText == string.Empty) {
                                this.MoveTo(this.incrSearchPosition);
                            } else {
                                this.selection.SetSelection(SelectionType.Stream, new Rectangle(this.Position.X, this.Position.Y, 0, 0));
                            }
                            this.Source.State |= NotifyState.IncrementalSearchChanged;
                        } finally {
                            this.Source.EndUpdate();
                        }
                    } else {
                        this.searchText = text;
                    }
                }
            } finally {
                this.incrSearchFlag = false;
            }
            return flag;
        }
        public virtual string GetTextToSearchAtCursor() {
            string text = this.Lines[this.Position.Y];
            string textAt;
            if (this.Position.X > 0 && this.Position.X < text.Length && this.Lines.IsDelimiter(text, this.Position.X) && !this.Lines.IsDelimiter(text, this.Position.X - 1)) {
                textAt = this.Lines.GetTextAt(this.Position.X - 1, this.Position.Y);
            } else {
                textAt = this.Lines.GetTextAt(this.Position);
            }
            return textAt;
        }
        public virtual bool CanSearchSelection(out string selectedText) {
            bool flag = !this.selection.IsEmpty;
            selectedText = (flag ? this.selection.SelectedText : string.Empty);
            return flag;
        }
        public virtual void ShowNotFound(string caption) {
            if ((this.searchOptions & SearchOptions.SilentSearch) == SearchOptions.None) {
                MessageBox.Show(string.Format(((this.searchOptions & SearchOptions.CycledSearch) != SearchOptions.None && !this.FirstSearch) ? StringConsts.SearchReachedStartPos : StringConsts.StringNotFound, this.searchText), caption);
            }
        }
        public virtual bool Find(string s, SearchOptions options, Regex expression, ref Point position, out int len, out Match match) {
            return this.Source.Lines.Find(s, options, expression, ref position, out len, out match);
        }


        private SyntaxSettings syntaxSettings;
        private SearchDialog searchDialog;
        private DlgSyntaxSettings editorSettingsDialog;
        private DlgGoto gotoLineDialog;

        [Category("SyntaxEdit"), Description("Represents an object that implements \"IPrinting\" interface allowing to perform various printing actions such as print, preview document, and setup print options."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content), TypeConverter(typeof(ExpandableObjectConverter))]
        public virtual Printing Printing {
            get {
                return this.printing;
            }
            set {
                if (this.printing != value) {
                    this.printing = value;
                    this.OnPrintingChanged();
                }
            }
        }





        private Printing printing;















        /// <summary>
        /// 显示滚动条。
        /// </summary>
        /// <param name="pos"></param>
        public virtual void ShowScrollHint(int pos) {
            this.CodeCompletionHint.Lexer = null;

            this.CodeCompletionHint.Provider = this.GetQuickInfo(string.Format(StringConsts.LineNofMstr, this.displayLines.DisplayPointToPoint(0, pos).Y + 1, this.Lines.Count), true);

            this.CodeCompletionHint.StartPos = new Point(-1, -1);
            this.CodeCompletionHint.EndPos = new Point(-1, -1);
            Point position = base.PointToScreen(new Point(base.Bounds.Width, 0));
            position.X -= this.CodeCompletionHint.Size.Width;
            position.Y = Math.Min(Cursor.Position.Y + this.Painter.FontHeight, base.PointToScreen(new Point(base.Bounds.Width, base.Bounds.Height)).Y);
            this.CodeCompletionHint.PopupAt(position);
            base.Update();
        }


        public virtual void HideScrollHint() {
            if (this.codeCompletionHint != null && this.codeCompletionHint.Visible) {
                this.codeCompletionHint.Close(false);
            }
        }

        private void ProcessPlayBack(MacroKeyData data) {
            if (data.Action != null) {
                data.Action();
            } else {
                if (data.ActionEx != null) {
                    data.ActionEx(data.Param);
                }
            }
        }

        public virtual bool MacroRecording {
            get {
                return this.macroRecording;
            }
            set {
                if (this.macroRecording != value) {
                    this.macroRecording = value;
                    this.OnMacroRecordingChanged();
                }
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual bool MacroSuspendend {
            get {
                return this.macroSuspended;
            }
            set {
                if (this.macroSuspended != value) {
                    this.macroSuspended = value;
                    this.OnMacroSuspendendChanged();
                }
            }
        }
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual MacroKeyList MacroRecords {
            get {
                return this.macroRecords;
            }
            set {
                this.macroRecords.Clear();
                foreach (MacroKeyData current in value) {
                    this.macroRecords.Add(current);
                }
                this.OnMacroRecordsChanged();
            }
        }
        protected virtual void OnMacroSuspendendChanged() {
        }
        protected virtual void OnMacroRecordsChanged() {
        }
        protected virtual void OnMacroRecordingChanged() {
            if (this.macroRecording && !this.macroSuspended) {
                this.macroRecords.Clear();
            }
        }
        public virtual void PlayBackMacro() {
            if (this.macroUpdateCount <= 0) {
                this.macroUpdateCount++;
                try {
                    this.macroRecording = false;
                    MacroKeyList macroKeyList = new MacroKeyList();
                    foreach (MacroKeyData current in this.macroRecords) {
                        macroKeyList.Add(current);
                    }
                    foreach (MacroKeyData current in macroKeyList) {
                        this.ProcessPlayBack(current);
                    }
                } finally {
                    this.macroUpdateCount--;
                }
            }
        }

        public virtual void StartMacroRecording() {
            this.MacroRecording = true;
        }
        public virtual void StopMacroRecording() {
            this.MacroRecording = false;
        }
        public virtual void PauseMacroRecording() {
            this.MacroSuspendend = true;
            this.MacroRecording = false;
        }
        public virtual void ResumeMacroRecording() {
            this.MacroRecording = true;
            this.MacroSuspendend = false;
        }
        public virtual void ToggleMacroRecording() {
            if (this.macroUpdateCount <= 0) {
                this.MacroRecording = !this.MacroRecording;
            }
        }
        public virtual void RecordKeyData(MacroKeyData keyData) {
            this.macroRecords.Add(keyData);
        }

        protected virtual void DoAutoCorrection(Point pos, string word, string correctWord) {
            this.Source.BeginUpdate(UpdateReason.Insert);
            int index = this.Source.StorePosition(this.Position);
            try {
                this.Source.Position = pos;
                this.Source.DeleteRight(word.Length);
                this.Source.Insert(correctWord);
            } finally {
                this.Position = this.Source.RestorePosition(index);
                this.Source.EndUpdate();
            }
        }
        protected virtual void CheckAutoCorrect(Point pos, string word) {
            if (word != string.Empty && (!this.Source.HasSpelling || !this.spelling.IsWordCorrect(word))) {
                string correctWord;
                if (this.HasAutoCorrection(word, out correctWord)) {
                    this.DoAutoCorrection(pos, word, correctWord);
                }
            }
        }
        protected virtual void CheckAutoCorrect() {
            if (this.lastKey != '\0') {
                if (this.autoCorrection && Array.IndexOf<char>(this.autoCorrectDelimiters, this.lastKey) >= 0) {
                    Point prevPosition = this.Source.PrevPosition;
                    string text = this.Lines[prevPosition.Y];
                    int num;
                    int num2;
                    if (this.Lines.GetWord(text, Math.Max(prevPosition.X - 1, 0), out num, out num2, this.Source.SpellTable)) {
                        this.CheckAutoCorrect(new Point(num, prevPosition.Y), text.Substring(num, num2 - num + 1));
                    }
                }
                this.lastKey = '\0';
            }
        }
        protected virtual void OnAutoCorrectDelimitersChanged() {
        }
        protected virtual void OnAutoCorrectionChanged() {
        }
        public virtual bool HasAutoCorrection(string word, out string correctWord) {
            bool result;
            if (this.AutoCorrect != null) {
                this.autoCorrectEventArgs.Word = word;
                this.autoCorrectEventArgs.CorrectWord = word;
                this.autoCorrectEventArgs.HasCorrection = false;
                this.AutoCorrect(this, this.autoCorrectEventArgs);
                correctWord = this.autoCorrectEventArgs.CorrectWord;
                result = this.autoCorrectEventArgs.HasCorrection;
            } else {
                correctWord = word;
                result = false;
            }
            return result;
        }

    }
}
